package com.zzyl.nursing.controller.member;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.dto.ReservationDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.service.IReservationService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 预约信息Controller
 *
 * @author zouguanghuan
 * @date 2025-10-28
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags = "预约信息相关接口")
public class ReservationController extends BaseController {
    @Autowired
    private IReservationService reservationService;

    /**
     *分页查询增加预约人姓名，手机号，状态，类型的查询条件
     */
//    @GetMapping("/page")
//    @ApiOperation(value = "分页查询预约")
//    public TableDataInfo<List<Reservation>> list(Reservation reservation) {
//        startPage();
//        List<Reservation> list = reservationService.selectReservationList(reservation);
//        return getDataTable(list);
//    }
    @GetMapping("/page")
    @ApiOperation("分页查询预约")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态", required = false, dataType = "int", paramType = "query"),
    })
    public R<TableDataInfo<Reservation>> findByPage(@RequestParam(defaultValue = "1") int pageNum,
                                                    @RequestParam(defaultValue = "10") int pageSize,
                                                    @RequestParam(required = false) Integer status) {
        TableDataInfo<Reservation> tableDataInfo = reservationService.selectByPage(pageNum, pageSize, status);
        return R.ok(tableDataInfo);
    }


    /**
     * 新增预约信息
     */
    @Log(title = "预约信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增预约信息")
    public R add(@ApiParam(value = "预约信息实体", required = true) @RequestBody ReservationDto dto) {
        reservationService.insertReservation(dto);
        return R.ok();
    }


    /**
     * 取消预约信息
     */
    @Log(title = "预约信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}/cancel")
    @ApiOperation("取消预约信息")
    public R remove(@ApiParam(value = "要删除的数据id") @PathVariable Long id) {
        reservationService.cancelReservation(id);
        return R.ok();
    }

    /**
     * 查询当天取消预约数量
     */
    @GetMapping(value = "/cancelled-count")
    @ApiOperation("当天取消预约数量")
    public R<Integer> cancelledCount() {
        return R.ok(reservationService.cancelledCount());
    }

    /**
     * 查询每个时间段剩余预约次数
     */
    @GetMapping(value = "/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public R countByTime(Long time) {
        return R.ok(reservationService.countByTime(time));
    }
}
